/*
 * @Author: daniel_du dll_2018@126.com
 * @Date: 2022-05-08 14:59:21
 * @LastEditors: daniel_du dll_2018@126.com
 * @LastEditTime: 2022-05-09 16:11:29
 * @FilePath: /safe_transmission_platform/tests/test_mysql.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "mysqldb.h"
void connectByCAPI()
{
    MYSQL mysql;
    mysql_init(&mysql);
    if (!mysql_real_connect(&mysql,"127.0.0.1","root","daniel","tests",3306,nullptr,0)){
        std::cout<<"connect failed!"<<std::endl;
    }
    else{
        std::cout<<"connect succeed!"<<std::endl;
    }
}

void connectByCPPAPI()
{
    daniel::MysqlInfo info;
    info.m_pwd = "daniel";
    info.m_database = "seckey";
    info.m_port = 3306;
    daniel::MysqlDB::ptr mysql(new daniel::MysqlDB(info));
    // std::vector<std::string> result;
    // mysql->excuteQuery("insert into employee values(18,'Jason',9500,4,25000)");
    // mysql->excuteDML("insert into employee values(18,'Jason',9500,4,25000)");
    mysql->connectToDB();
    daniel::MysqlDB::PrintResult(mysql->excuteQuery("show tables"));
    daniel::MysqlDB::PrintResult(mysql->excuteQuery("select * from secretKey;"));
}

int main()
{
    connectByCAPI();
    connectByCPPAPI();
}